package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysArticleMapper;
import com.ruoyi.system.domain.SysArticle;
import com.ruoyi.system.service.ISysArticleService;

/**
 * 物品Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-11
 */
@Service
public class SysArticleServiceImpl implements ISysArticleService 
{
    @Autowired
    private SysArticleMapper sysArticleMapper;

    /**
     * 查询物品
     * 
     * @param id 物品主键
     * @return 物品
     */
    @Override
    public SysArticle selectSysArticleById(Long id)
    {
        return sysArticleMapper.selectSysArticleById(id);
    }
    /**
     * 查询物品列表
     * 
     * @param sysArticle 物品
     * @return 物品
     */
    @Override
    public List<SysArticle> selectSysArticleList(SysArticle sysArticle)
    {
        return sysArticleMapper.selectSysArticleList(sysArticle);
    }
    /**
     * 新增物品
     * 
     * @param sysArticle 物品
     * @return 结果
     */
    @Override
    public int insertSysArticle(SysArticle sysArticle)
    {
        sysArticle.setCreateTime(DateUtils.getNowDate());
        SysArticle list1= new SysArticle();
        list1.setArticleid(sysArticle.getArticleid());
        list1.setUserId(sysArticle.getUserId());
        List<SysArticle> info= sysArticleMapper.selectSysArticleList(list1);
        if(info.size() > 0) { 
        	for (SysArticle article : info) {  
        	    Long num = article.getNum(); 
        	    article.setNum(num + 1);
        	    System.err.println(article);
        	    return sysArticleMapper.updateSysArticle(article);	
        	}
        }else {
        	  return sysArticleMapper.insertSysArticle(sysArticle);	
        }     
		return 0;
        
    }
    /**
     * 修改物品
     * 
     * @param sysArticle 物品
     * @return 结果
     */
    @Override
    public int updateSysArticle(SysArticle sysArticle)
    {
        return sysArticleMapper.updateSysArticle(sysArticle);
    }

    /**
     * 批量删除物品
     * 
     * @param ids 需要删除的物品主键
     * @return 结果
     */
    @Override
    public int deleteSysArticleByIds(Long[] ids)
    {
        return sysArticleMapper.deleteSysArticleByIds(ids);
    }

    /**
     * 删除物品信息
     * 
     * @param id 物品主键
     * @return 结果
     */
    @Override
    public int deleteSysArticleById(Long id)
    {
        return sysArticleMapper.deleteSysArticleById(id);
    }
}
